package com.infitecs.eyas.suction.service;

import com.infitecs.eyas.session.SessionService;
import com.infitecs.eyas.suction.dao.SuctionCalcaulatorBaseDao;
import com.infitecs.eyas.suction.dao.SuctionCalculatorDao;
import com.infitecs.eyas.suction.model.SuctionCalculate;
import com.infitecs.eyas.suction.model.SunctionCalcalatorBase;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by pzw on 2015/8/4.
 */
@Service
public class SuctionCalculatorServices {

    @Autowired
    private SessionService sessionService;

    @Autowired
    private SuctionCalculatorDao suctionCalculatorDao;

    @Autowired
    private SuctionCalcaulatorBaseDao suctionCalcaulatorBaseDao;

    public void insertSuctionCalculator() {
        int caseId = sessionService.getCaseId();
        SuctionCalculate suctionCalculate = new SuctionCalculate();
        suctionCalculate.setCaseId(caseId);
        suctionCalculate.setClassA("btn green addable");
        suctionCalculate.setClassI("fa fa-plus");
        for (int i = 1; i <= 7; i++) {
            suctionCalculate.setLagreType(1);
            switch (i) {
                case 1:
                    suctionCalculate.setSmallType(i);
                    suctionCalculate.setTitle("管段1");
                    suctionCalculatorDao.insertSuctionCalculator(suctionCalculate);
                    break;
                case 2:
                    suctionCalculate.setSmallType(i);
                    suctionCalculate.setTitle("零件1");
                    suctionCalculatorDao.insertSuctionCalculator(suctionCalculate);
                    break;
                case 3:
                    suctionCalculate.setSmallType(i);
                    suctionCalculate.setTitle("部件1");
                    suctionCalculatorDao.insertSuctionCalculator(suctionCalculate);
                    break;
                case 4:
                    suctionCalculate.setSmallType(i);
                    suctionCalculate.setTitle("设备1");
                    suctionCalculatorDao.insertSuctionCalculator(suctionCalculate);
                    break;
                case 5:
                    suctionCalculate.setSmallType(i);
                    suctionCalculate.setTitle("提升压头损失");
                    suctionCalculatorDao.insertSuctionCalculator(suctionCalculate);
                    break;
                case 6:
                    suctionCalculate.setSmallType(i);
                    suctionCalculate.setTitle("加速损失");
                    suctionCalculatorDao.insertSuctionCalculator(suctionCalculate);
                    break;
                case 7:
                    suctionCalculate.setSmallType(i);
                    suctionCalculate.setTitle("自生通风");
                    suctionCalculatorDao.insertSuctionCalculator(suctionCalculate);
                    break;
            }
        }
        for (int i = 1; i <= 7; i++) {
            suctionCalculate.setLagreType(2);
            switch (i) {
                case 1:
                    suctionCalculate.setSmallType(i);
                    suctionCalculate.setTitle("管段1");
                    suctionCalculatorDao.insertSuctionCalculator(suctionCalculate);
                    break;
                case 2:
                    suctionCalculate.setSmallType(i);
                    suctionCalculate.setTitle("零件1");
                    suctionCalculatorDao.insertSuctionCalculator(suctionCalculate);
                    break;
                case 3:
                    suctionCalculate.setSmallType(i);
                    suctionCalculate.setTitle("部件1");
                    suctionCalculatorDao.insertSuctionCalculator(suctionCalculate);
                    break;
                case 4:
                    suctionCalculate.setSmallType(i);
                    suctionCalculate.setTitle("设备1");
                    suctionCalculatorDao.insertSuctionCalculator(suctionCalculate);
                    break;
                case 5:
                    suctionCalculate.setSmallType(i);
                    suctionCalculate.setTitle("提升压头损失");
                    suctionCalculatorDao.insertSuctionCalculator(suctionCalculate);
                    break;
                case 6:
                    suctionCalculate.setSmallType(i);
                    suctionCalculate.setTitle("加速损失");
                    suctionCalculatorDao.insertSuctionCalculator(suctionCalculate);
                    break;
                case 7:
                    suctionCalculate.setSmallType(i);
                    suctionCalculate.setTitle("自生通风");
                    suctionCalculatorDao.insertSuctionCalculator(suctionCalculate);
                    break;
            }
        }
    }


    public List<SuctionCalculate> getSuctionCalculatorList() {
        return suctionCalculatorDao.getSuctionCalculator(sessionService.getCaseId());
    }

    public List<SuctionCalculate> getIn() {
        return suctionCalculatorDao.getIn(sessionService.getCaseId());
    }

    public List<SuctionCalculate> getOut() {
        return suctionCalculatorDao.getOut(sessionService.getCaseId());
    }

    public int insertOneSuction(SuctionCalculate suctionCalculate) {
        suctionCalculate.setCaseId(sessionService.getCaseId());
        suctionCalculatorDao.insertSuctionCalculator(suctionCalculate);
        return suctionCalculate.getId();
    }

    public void del(int id) {
        suctionCalculatorDao.del(id);
    }

    public void editTitle(SuctionCalculate suctionCalculate) {
        suctionCalculatorDao.editTitle(suctionCalculate);
    }

    public void update(SuctionCalculate suctionCalculate) {
        suctionCalculatorDao.update(suctionCalculate);
    }

    public SunctionCalcalatorBase getSunctionCalculator() {
        return suctionCalcaulatorBaseDao.getSuctionCalaulatorBaseByCaseId(sessionService.getCaseId());
    }

    public void insertNewSuctionBase() {
        suctionCalcaulatorBaseDao.insertNew(sessionService.getCaseId());
    }

    public void updateAll(SunctionCalcalatorBase sunctionCalcalatorBase) {
        suctionCalcaulatorBaseDao.updateAll(sunctionCalcalatorBase);
    }

    public void updateParam(SunctionCalcalatorBase sunctionCalcalatorBase) {
        suctionCalcaulatorBaseDao.updateParam(sunctionCalcalatorBase);
    }

}
